﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using MsTestUtilities.SolutionAnalysis.Testing;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace SolutionSetupTests
{
    [TestClass]
    public class TestSetup
    {
        [AssemblyInitialize]
        public static void SolutionTestSetup(TestContext context)
        {
            var file = File.ReadLines("SolutionPath.txt")
                .First()
                .Trim();

            SolutionAssert.SetSolutionFile(file);
        }

        [TestMethod]
        public void WarningsTreatedAsErrors()
        {
            SolutionAssert
                .ForAllProjects()
                .ForAllConfigurations()
                .WarningsTreatedAsErrors();
        }

        [TestMethod, Ignore]
        public void OutputDirectoryTests()
        {
            SolutionAssert
                .ForNonTestProjects()
                .ForAllConfigurations()
                .OutputIsUnder(@"Bin");
        }

        [TestMethod]
        public void NoProjectsShouldBeReferencedAsAssemblies()
        {
            var projectOutputs = SolutionAssert.Solution
                .Projects
                .Select(p => p.AssemblyName)
                .ToList();

            SolutionAssert
                .ForAllProjects()
                .ForAllReferences()
                .Satisfies(r => r.Include, i => !projectOutputs.Contains(i));
        }

        [TestMethod]
        public void NoProjectsShouldBeReferencedAsAssemblies2()
        {
            var projectOutputs = SolutionAssert.Solution
                .Projects
                .Select(p => p.AssemblyName)
                .ToList();

            SolutionAssert
                .ForAllProjects()
                .ForAllReferences()
                .IsNotIn(projectOutputs);
        }
    }
}
